package com.tjh.springbootapi.controller;

import com.koala.apiprototype.annotations.IgnoreValidate;
import com.tjh.springbootapi.entity.UserInfo;
import com.tjh.springbootapi.service.UserInfoService;
import com.tjh.springbootapi.utils.FileDownloadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * Create by koala on 2020-03-21
 */
@RestController
@RequestMapping("/import")
public class ImportController {

    @Autowired
    UserInfoService userInfoService;

    /**
     * 下载导入模板
     *
     * @param response
     */
    @IgnoreValidate
    @RequestMapping(value = "/downTemplate")
    public void downTemplate(HttpServletResponse response) {
        FileDownloadUtil.downTemplate(response, "/templates/导入模板.xlsx");
    }

    /**
     * 导入用户信息
     *
     * @param userInfoList
     * @return
     */
    @IgnoreValidate
    @PostMapping("/importUserInfo")
    public HashMap importUserInfo(@RequestBody List<UserInfo> userInfoList) {
        return userInfoService.importUserInfo(userInfoList);
    }

}
